home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Windows 95 API Bible
/
Windows 95 API Bible 3 Disc Set.iso
/
Win32 API Bible Book 1 of 3
/
CHAPTE21
/
EX12.C
< prev
next >
Wrap
C/C++ Source or Header
|
1995-05-29
|
2KB
|
44 lines
#include <genstub.c>
#include <pbt.h>
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_COMMAND:
switch ( LOWORD( wParam ) )
{
case IDM_TEST: // Query suspend power.
SetSystemPowerState( FALSE, FALSE );
break;
case IDM_EXIT:
DestroyWindow( hWnd );
break;
}
break;
case WM_POWERBROADCAST:
if ( wParam == PBT_APMQUERYSUSPEND )
{
SYSTEM_POWER_STATUS sps;
GetSystemPowerStatus( &sps );
// if not on ACLine & less than 10 percent, let suspend.
if (!sps.ACLineStatus && sps.BatteryLifePercent<10 )
{
int iResponse = MessageBox( hWnd, "Do you want to suspend?",
"Query Suspend State", MB_YESNO );
if ( iResponse == IDYES )
return TRUE;
else
return FALSE;
}
}
return (DefWindowProc(hWnd, uMsg, wParam, lParam));
case WM_DESTROY:
PostQuitMessage( 0 );
break;
default:
return (DefWindowProc(hWnd, uMsg, wParam, lParam));
}
return (NULL);
}